package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.PageQueryDto;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.MemberReservationService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户预约管理控制层
 * @author: JBY
 * @since: 2025/08/22 14:25
 */
@RestController
@RequestMapping("/member/reservation")
@Slf4j
@Api(tags = "C端预约管理")
public class MemberReservationController {

    @Autowired
    private MemberReservationService memberReservationService;

    /**
     * 查询当天取消预约数量
     * @param
     * @return
     */
    @GetMapping("/cancelled-count")
    public AjaxResult getCancelledCount() {
        return AjaxResult.success(memberReservationService.getCancelledCount());
    }

    /**
     * 查询每个时间段剩余预约次数
     * @param
     * @return
     */
    @GetMapping("/countByTime")
    public AjaxResult getCountByTime(Long time) {
        return AjaxResult.success(memberReservationService.getCountByTime(time));
    }

    /**
     * 新增预约
     * @param ReservationDto
     * @return AjaxResult
     */
    @PostMapping
    public AjaxResult add(@RequestBody ReservationDto ReservationDto) {
        return AjaxResult.success(memberReservationService.add(ReservationDto));
    }

    /**
     * 分页查询预约
     * @param pageQueryDto
     * @return TableDataInfo
     */
    @GetMapping("/page")
    public TableDataInfo<Reservation> pageQuery(PageQueryDto pageQueryDto) {
        return memberReservationService.pageQuery(pageQueryDto);
    }

    /**
     * 取消预约
     * @param id
     * @return AjaxResult
     */
    @PutMapping("/{id}/cancel")
    public AjaxResult cancel(@PathVariable Long id) {
        boolean result = memberReservationService.cancel(id);
        return result ? AjaxResult.success("取消预约成功") : AjaxResult.error("取消预约失败");
    }
}
